using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
namespace SHDocVw
{
	internal sealed class DShellNameSpaceEvents_EventProvider : DShellNameSpaceEvents_Event, IDisposable
	{
		private IConnectionPointContainer m_ConnectionPointContainer;
		private ArrayList m_aEventSinkHelpers;
		private IConnectionPoint m_ConnectionPoint;
		private void Init()
		{
			IConnectionPoint connectionPoint = null;
			Guid guid = new Guid(new byte[]
			{
				6,
				104,
				19,
				85,
				222,
				178,
				209,
				17,
				185,
				242,
				0,
				160,
				201,
				139,
				197,
				71
			});
			this.m_ConnectionPointContainer.FindConnectionPoint(ref guid, out connectionPoint);
			this.m_ConnectionPoint = (IConnectionPoint)connectionPoint;
			this.m_aEventSinkHelpers = new ArrayList();
		}
		public override void add_FavoritesSelectionChange(DShellNameSpaceEvents_FavoritesSelectionChangeEventHandler favoritesSelectionChangeDelegate)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_ConnectionPoint == null)
				{
					this.Init();
				}
				DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper = new DShellNameSpaceEvents_SinkHelper();
				int dwCookie = 0;
				this.m_ConnectionPoint.Advise((object)dShellNameSpaceEvents_SinkHelper, out dwCookie);
				dShellNameSpaceEvents_SinkHelper.m_dwCookie = dwCookie;
				dShellNameSpaceEvents_SinkHelper.m_FavoritesSelectionChangeDelegate = favoritesSelectionChangeDelegate;
				this.m_aEventSinkHelpers.Add((object)dShellNameSpaceEvents_SinkHelper);
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void remove_FavoritesSelectionChange(DShellNameSpaceEvents_FavoritesSelectionChangeEventHandler dShellNameSpaceEvents_FavoritesSelectionChangeEventHandler)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_aEventSinkHelpers != null)
				{
					int count = this.m_aEventSinkHelpers.Count;
					int num = 0;
					if (0 < count)
					{
						DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper;
						while (true)
						{
							dShellNameSpaceEvents_SinkHelper = (DShellNameSpaceEvents_SinkHelper)this.m_aEventSinkHelpers[num];
							if (dShellNameSpaceEvents_SinkHelper.m_FavoritesSelectionChangeDelegate != null && ((dShellNameSpaceEvents_SinkHelper.m_FavoritesSelectionChangeDelegate.Equals((object)dShellNameSpaceEvents_FavoritesSelectionChangeEventHandler) ? 1 : 0) & 255) != 0)
							{
								break;
							}
							num++;
							if (num >= count)
							{
								goto IL_E1;
							}
						}
						this.m_aEventSinkHelpers.RemoveAt(num);
						this.m_ConnectionPoint.Unadvise(dShellNameSpaceEvents_SinkHelper.m_dwCookie);
						if (count <= 1)
						{
							Marshal.ReleaseComObject(this.m_ConnectionPoint);
							this.m_ConnectionPoint = null;
							this.m_aEventSinkHelpers = null;
						}
					}
				}
				IL_E1:;
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void add_SelectionChange(DShellNameSpaceEvents_SelectionChangeEventHandler selectionChangeDelegate)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_ConnectionPoint == null)
				{
					this.Init();
				}
				DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper = new DShellNameSpaceEvents_SinkHelper();
				int dwCookie = 0;
				this.m_ConnectionPoint.Advise((object)dShellNameSpaceEvents_SinkHelper, out dwCookie);
				dShellNameSpaceEvents_SinkHelper.m_dwCookie = dwCookie;
				dShellNameSpaceEvents_SinkHelper.m_SelectionChangeDelegate = selectionChangeDelegate;
				this.m_aEventSinkHelpers.Add((object)dShellNameSpaceEvents_SinkHelper);
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void remove_SelectionChange(DShellNameSpaceEvents_SelectionChangeEventHandler dShellNameSpaceEvents_SelectionChangeEventHandler)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_aEventSinkHelpers != null)
				{
					int count = this.m_aEventSinkHelpers.Count;
					int num = 0;
					if (0 < count)
					{
						DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper;
						while (true)
						{
							dShellNameSpaceEvents_SinkHelper = (DShellNameSpaceEvents_SinkHelper)this.m_aEventSinkHelpers[num];
							if (dShellNameSpaceEvents_SinkHelper.m_SelectionChangeDelegate != null && ((dShellNameSpaceEvents_SinkHelper.m_SelectionChangeDelegate.Equals((object)dShellNameSpaceEvents_SelectionChangeEventHandler) ? 1 : 0) & 255) != 0)
							{
								break;
							}
							num++;
							if (num >= count)
							{
								goto IL_E1;
							}
						}
						this.m_aEventSinkHelpers.RemoveAt(num);
						this.m_ConnectionPoint.Unadvise(dShellNameSpaceEvents_SinkHelper.m_dwCookie);
						if (count <= 1)
						{
							Marshal.ReleaseComObject(this.m_ConnectionPoint);
							this.m_ConnectionPoint = null;
							this.m_aEventSinkHelpers = null;
						}
					}
				}
				IL_E1:;
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void add_DoubleClick(DShellNameSpaceEvents_DoubleClickEventHandler doubleClickDelegate)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_ConnectionPoint == null)
				{
					this.Init();
				}
				DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper = new DShellNameSpaceEvents_SinkHelper();
				int dwCookie = 0;
				this.m_ConnectionPoint.Advise((object)dShellNameSpaceEvents_SinkHelper, out dwCookie);
				dShellNameSpaceEvents_SinkHelper.m_dwCookie = dwCookie;
				dShellNameSpaceEvents_SinkHelper.m_DoubleClickDelegate = doubleClickDelegate;
				this.m_aEventSinkHelpers.Add((object)dShellNameSpaceEvents_SinkHelper);
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void remove_DoubleClick(DShellNameSpaceEvents_DoubleClickEventHandler dShellNameSpaceEvents_DoubleClickEventHandler)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_aEventSinkHelpers != null)
				{
					int count = this.m_aEventSinkHelpers.Count;
					int num = 0;
					if (0 < count)
					{
						DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper;
						while (true)
						{
							dShellNameSpaceEvents_SinkHelper = (DShellNameSpaceEvents_SinkHelper)this.m_aEventSinkHelpers[num];
							if (dShellNameSpaceEvents_SinkHelper.m_DoubleClickDelegate != null && ((dShellNameSpaceEvents_SinkHelper.m_DoubleClickDelegate.Equals((object)dShellNameSpaceEvents_DoubleClickEventHandler) ? 1 : 0) & 255) != 0)
							{
								break;
							}
							num++;
							if (num >= count)
							{
								goto IL_E1;
							}
						}
						this.m_aEventSinkHelpers.RemoveAt(num);
						this.m_ConnectionPoint.Unadvise(dShellNameSpaceEvents_SinkHelper.m_dwCookie);
						if (count <= 1)
						{
							Marshal.ReleaseComObject(this.m_ConnectionPoint);
							this.m_ConnectionPoint = null;
							this.m_aEventSinkHelpers = null;
						}
					}
				}
				IL_E1:;
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void add_Initialized(DShellNameSpaceEvents_InitializedEventHandler initializedDelegate)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_ConnectionPoint == null)
				{
					this.Init();
				}
				DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper = new DShellNameSpaceEvents_SinkHelper();
				int dwCookie = 0;
				this.m_ConnectionPoint.Advise((object)dShellNameSpaceEvents_SinkHelper, out dwCookie);
				dShellNameSpaceEvents_SinkHelper.m_dwCookie = dwCookie;
				dShellNameSpaceEvents_SinkHelper.m_InitializedDelegate = initializedDelegate;
				this.m_aEventSinkHelpers.Add((object)dShellNameSpaceEvents_SinkHelper);
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void remove_Initialized(DShellNameSpaceEvents_InitializedEventHandler dShellNameSpaceEvents_InitializedEventHandler)
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_aEventSinkHelpers != null)
				{
					int count = this.m_aEventSinkHelpers.Count;
					int num = 0;
					if (0 < count)
					{
						DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper;
						while (true)
						{
							dShellNameSpaceEvents_SinkHelper = (DShellNameSpaceEvents_SinkHelper)this.m_aEventSinkHelpers[num];
							if (dShellNameSpaceEvents_SinkHelper.m_InitializedDelegate != null && ((dShellNameSpaceEvents_SinkHelper.m_InitializedDelegate.Equals((object)dShellNameSpaceEvents_InitializedEventHandler) ? 1 : 0) & 255) != 0)
							{
								break;
							}
							num++;
							if (num >= count)
							{
								goto IL_E1;
							}
						}
						this.m_aEventSinkHelpers.RemoveAt(num);
						this.m_ConnectionPoint.Unadvise(dShellNameSpaceEvents_SinkHelper.m_dwCookie);
						if (count <= 1)
						{
							Marshal.ReleaseComObject(this.m_ConnectionPoint);
							this.m_ConnectionPoint = null;
							this.m_aEventSinkHelpers = null;
						}
					}
				}
				IL_E1:;
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public DShellNameSpaceEvents_EventProvider(object obj)
		{
			this.m_ConnectionPointContainer = (IConnectionPointContainer)obj;
		}
		public override void Finalize()
		{
			Monitor.Enter(this);
			try
			{
				if (this.m_ConnectionPoint != null)
				{
					int count = this.m_aEventSinkHelpers.Count;
					int num = 0;
					if (0 < count)
					{
						do
						{
							DShellNameSpaceEvents_SinkHelper dShellNameSpaceEvents_SinkHelper = (DShellNameSpaceEvents_SinkHelper)this.m_aEventSinkHelpers[num];
							this.m_ConnectionPoint.Unadvise(dShellNameSpaceEvents_SinkHelper.m_dwCookie);
							num++;
						}
						while (num < count);
					}
					Marshal.ReleaseComObject(this.m_ConnectionPoint);
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				Monitor.Exit(this);
			}
		}
		public override void Dispose()
		{
			this.Finalize();
			GC.SuppressFinalize(this);
		}
	}
}
